home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / lists / mint / l_1599 / 1415 < prev    next >
Encoding:
Internet Message Format  |  1994-08-27  |  11.0 KB

  1. From: Kay Roemer <roemer@informatik.uni-frankfurt.de>
  2. Posted-Date: Fri, 20 May 94 8:38:47 MESZ
  3. Received-Date: Fri, 20 May 94 08:38:47 +0200
  4. Message-Id: <9405200638.AA16329@hera.rbi.informatik.uni-frankfurt.de>
  5. Subject: addroottimeout() patches v2
  6. To: mint@atari.archive.umich.edu
  7. Date: Fri, 20 May 94 8:38:47 MESZ
  8. Mailer: Elm [revision: 70.85]
  9.  
  10. These are the patches that bring addroottimeout() and cancelroottimeout()
  11. to Mint 1.10.
  12.  
  13. They fix a bug in the previous release of the patches. Please update your
  14. version of Mint.
  15.  
  16. Kay.
  17.  
  18.  
  19. *** file.h.orig    Sun Mar 20 19:08:10 1994
  20. --- file.h    Wed May 18 23:01:32 1994
  21. ***************
  22. *** 243,251 ****
  23.   /* functions for adding/cancelling timeouts */
  24.       struct timeout * ARGS_ON_STACK (*addtimeout) P_((long, void (*)()));
  25.       void    ARGS_ON_STACK (*canceltimeout) P_((struct timeout *));
  26.    
  27.   /* reserved for future use */
  28. !     long    res2[7];
  29.   };
  30.   
  31.   /* flags for open() modes */
  32. --- 243,253 ----
  33.   /* functions for adding/cancelling timeouts */
  34.       struct timeout * ARGS_ON_STACK (*addtimeout) P_((long, void (*)()));
  35.       void    ARGS_ON_STACK (*canceltimeout) P_((struct timeout *));
  36. +     struct timeout * ARGS_ON_STACK (*addroottimeout) P_((long, void (*)(), short));
  37. +     void    ARGS_ON_STACK (*cancelroottimeout) P_((struct timeout *));
  38.    
  39.   /* reserved for future use */
  40. !     long    res2[5];
  41.   };
  42.   
  43.   /* flags for open() modes */
  44. *** main.c.orig    Sun Mar 20 19:07:52 1994
  45. --- main.c    Wed May 18 23:00:44 1994
  46. ***************
  47. *** 193,199 ****
  48.       strnicmp, stricmp, strlwr, strupr, ksprintf,
  49.       ms_time, unixtim, dostim,
  50.       nap, sleep, wake, wakeselect,
  51. !     denyshare, denylock, addtimeout, canceltimeout
  52.   };
  53.   
  54.   /* table of processor frame sizes in _words_ (not used on MC68000) */
  55. --- 193,200 ----
  56.       strnicmp, stricmp, strlwr, strupr, ksprintf,
  57.       ms_time, unixtim, dostim,
  58.       nap, sleep, wake, wakeselect,
  59. !     denyshare, denylock, addtimeout, canceltimeout,
  60. !     addroottimeout, cancelroottimeout
  61.   };
  62.   
  63.   /* table of processor frame sizes in _words_ (not used on MC68000) */
  64. *** proc.h.orig    Sun Mar 20 19:08:10 1994
  65. --- proc.h    Sun Mar 20 19:07:40 1994
  66. ***************
  67. *** 67,72 ****
  68. --- 67,73 ----
  69.       struct proc    *proc;
  70.       long    when;
  71.       void    (*func) P_((struct proc *)); /* function to call at timeout */
  72. +     short    flags;
  73.   } TIMEOUT;
  74.   
  75.   #ifndef GENMAGIC
  76. *** proto.h.orig    Sun Mar 20 19:08:10 1994
  77. --- proto.h    Wed May 18 22:59:42 1994
  78. ***************
  79. *** 274,281 ****
  80. --- 274,283 ----
  81.   
  82.   /* timeout.c */
  83.   TIMEOUT * ARGS_ON_STACK addtimeout P_((long delta, void (*func)(PROC *p)));
  84. + TIMEOUT * ARGS_ON_STACK addroottimeout P_((long delta, void (*func)(PROC *p), short flags));
  85.   void ARGS_ON_STACK cancelalltimeouts P_((void));
  86.   void ARGS_ON_STACK canceltimeout P_((TIMEOUT *which));
  87. + void ARGS_ON_STACK cancelroottimeout P_((TIMEOUT *which));
  88.   void ARGS_ON_STACK timeout P_((void));
  89.   void checkalarms P_((void));
  90.   void ARGS_ON_STACK nap P_((unsigned n));
  91. *** timeout.c.orig    Sun Mar 20 19:07:52 1994
  92. --- timeout.c    Wed May 18 22:58:18 1994
  93. ***************
  94. *** 19,55 ****
  95.   extern short in_kernel;    /* in main.c */
  96.   
  97.   static void unnapme P_((PROC *));
  98.   
  99. ! /*
  100. !  * addtimeout(long delta, void (*func)()): schedule a timeout for the current
  101. !  * process, to take place in "delta" milliseconds. "func" specifies a
  102. !  * function to be called at that time; the function is passed as a parameter
  103. !  * the process for which the timeout was specified (i.e. the value of
  104. !  * curproc at the time addtimeout() was called; note that this is probably
  105. !  * *not* the current process when the timeout occurs).
  106.    */
  107. ! TIMEOUT *tlist;
  108.   
  109. - #define newtimeout() (TIMEOUT *)kmalloc(SIZEOF(TIMEOUT))
  110. - #define disposetimeout(t) kfree(t)
  111.   
  112. ! TIMEOUT * ARGS_ON_STACK
  113. ! addtimeout(delta, func)
  114. !     long delta;
  115. !     void (*func) P_((PROC *));
  116.   {
  117. !     TIMEOUT *t, **prev, *cur;
  118.   
  119. !     t = newtimeout();
  120.   
  121. ! /* BUG: we should have some fallback mechanism for timeouts when the
  122. !    kernel memory is exhausted
  123. !  */
  124. !     assert(t);
  125.   
  126. !     t->proc = curproc;
  127. !     t->func = func;
  128.   
  129.       cur = tlist;
  130.       prev = &tlist;
  131. --- 19,80 ----
  132.   extern short in_kernel;    /* in main.c */
  133.   
  134.   static void    unnapme P_((PROC *));
  135. + static TIMEOUT    *newtimeout P_((short));
  136. + static void    disposetimeout P_((TIMEOUT *));
  137. + static void    inserttimeout P_ ((TIMEOUT *, long));
  138. + #define TIMEOUTS    20    /* # of static timeout structs */
  139. + #define TIMEOUT_USED    0x01    /* timeout struct is in use */
  140. + #define TIMEOUT_STATIC    0x02    /* this is a static timeout */
  141.   
  142. ! /* This gets implizitly initialized to zero, thus the flags are
  143. !  * set up correctly.
  144.    */
  145. ! static TIMEOUT timeouts[TIMEOUTS] = { { 0, }, };
  146. ! TIMEOUT *tlist = NULL;
  147.   
  148.   
  149. ! static TIMEOUT *
  150. ! newtimeout(fromlist)
  151. !     short fromlist;
  152.   {
  153. !     TIMEOUT *t;
  154. !     short i, sr;
  155.   
  156. !     if (!fromlist) {
  157. !         t = kmalloc(SIZEOF(TIMEOUT));
  158. !         if (t) {
  159. !             t->flags = 0;
  160. !             return t;
  161. !         }
  162. !     }
  163. !     sr = spl7();
  164. !     for (i = 0; i < TIMEOUTS; ++i) {
  165. !         if (!(timeouts[i].flags & TIMEOUT_USED)) {
  166. !             timeouts[i].flags |= (TIMEOUT_STATIC|TIMEOUT_USED);
  167. !             spl(sr);
  168. !             return &timeouts[i];
  169. !         }
  170. !     }
  171. !     spl(sr);
  172. !     return 0;
  173. ! }
  174.   
  175. ! static void
  176. ! disposetimeout(t)
  177. !     TIMEOUT *t;
  178. ! {
  179. !     if (t->flags & TIMEOUT_STATIC) t->flags &= ~TIMEOUT_USED;
  180. !     else kfree(t);
  181. ! }
  182.   
  183. ! static void
  184. ! inserttimeout(t, delta)
  185. !     TIMEOUT *t;
  186. !     long delta;
  187. ! {
  188. !     TIMEOUT **prev, *cur;
  189. !     short sr = spl7();
  190.   
  191.       cur = tlist;
  192.       prev = &tlist;
  193. ***************
  194. *** 59,65 ****
  195.               t->next = cur;
  196.               t->when = delta;
  197.               *prev = t;
  198. !             return t;
  199.           }
  200.           delta -= cur->when;
  201.           prev = &cur->next;
  202. --- 84,91 ----
  203.               t->next = cur;
  204.               t->when = delta;
  205.               *prev = t;
  206. !             spl(sr);
  207. !             return;
  208.           }
  209.           delta -= cur->when;
  210.           prev = &cur->next;
  211. ***************
  212. *** 69,74 ****
  213. --- 95,167 ----
  214.       t->when = delta;
  215.       t->next = cur;
  216.       *prev = t;
  217. +     spl(sr);
  218. + }
  219. +     
  220. + /*
  221. +  * addtimeout(long delta, void (*func)()): schedule a timeout for the current
  222. +  * process, to take place in "delta" milliseconds. "func" specifies a
  223. +  * function to be called at that time; the function is passed as a parameter
  224. +  * the process for which the timeout was specified (i.e. the value of
  225. +  * curproc at the time addtimeout() was called; note that this is probably
  226. +  * *not* the current process when the timeout occurs).
  227. +  *
  228. +  * NOTE: if kernel memory is low, newtimeout() will try to get a statically
  229. +  * allocated timeout struct (fallback method).
  230. +  */
  231. + TIMEOUT * ARGS_ON_STACK
  232. + addtimeout(delta, func)
  233. +     long delta;
  234. +     void (*func) P_((PROC *));
  235. + {
  236. +     TIMEOUT *t;
  237. +     t = newtimeout(0);
  238. + /* BUG: we should have some fallback mechanism for timeouts when the
  239. +    kernel memory is exhausted
  240. +  */
  241. +     assert(t);
  242. +     t->proc = curproc;
  243. +     t->func = func;
  244. +     inserttimeout(t, delta);
  245. +     return t;
  246. + }
  247. + /*
  248. +  * addroottimeout(long delta, void (*)(PROC *), short flags);
  249. +  * Same as addtimeout(), except that the timeout is attached to Pid 0 (MiNT).
  250. +  * This means the timeout won't be cancelled if the process which was
  251. +  * running at the time addroottimeout() was called exits.
  252. +  *
  253. +  * Currently only bit 0 of `flags' is used. Meaning:
  254. +  * Bit 0 set: Call from interrupt (cannot use kmalloc, use statically
  255. +  *    allocated `struct timeout' instead).
  256. +  * Bit 0 clear: Not called from interrupt, can use kmalloc.
  257. +  *
  258. +  * Thus addroottimeout() can be called from interrupts (bit 0 of flags set),
  259. +  * which makes it *extremly* useful for device drivers.
  260. +  * A serial device driver would make an addroottimeout(0, check_keys, 1)
  261. +  * if some bytes have arrived.
  262. +  * check_keys() is then called at the next context switch, can use all
  263. +  * the kernel functions and can do time cosuming jobs.
  264. +  */
  265. + TIMEOUT * ARGS_ON_STACK
  266. + addroottimeout(delta, func, flags)
  267. +     long delta;
  268. +     void (*func) P_((PROC *));
  269. +     short flags;
  270. + {
  271. +     TIMEOUT *t;
  272. +     t = newtimeout(flags & 1);
  273. +     if (!t) return NULL;
  274. +     t->proc = rootproc;
  275. +     t->func = func;
  276. +     inserttimeout(t, delta);
  277.       return t;
  278.   }
  279.   
  280. ***************
  281. *** 82,87 ****
  282. --- 175,181 ----
  283.   {
  284.       TIMEOUT *cur, **prev, *old;
  285.       long delta;
  286. +     short sr = spl7 ();
  287.   
  288.       cur = tlist;
  289.       prev = &tlist;
  290. ***************
  291. *** 91,103 ****
  292. --- 185,203 ----
  293.               old = cur;
  294.               *prev = cur = cur->next;
  295.               if (cur) cur->when += delta;
  296. +             spl(sr);
  297.               disposetimeout(old);
  298. +             sr = spl7();
  299. +         /* ++kay: just in case an interrupt handler installed a
  300. +          * timeout right after `prev' and before `cur' */
  301. +             cur = *prev;
  302.           }
  303.           else {
  304.               prev = &cur->next;
  305.               cur = cur->next;
  306.           }
  307.       }
  308. +     spl (sr);
  309.   }
  310.   
  311.   /*
  312. ***************
  313. *** 115,133 ****
  314.       TIMEOUT *this;
  315.   {
  316.       TIMEOUT *cur, **prev;
  317.   
  318.       prev = &tlist;
  319.       for (cur = tlist; cur; cur = cur->next) {
  320. !         if (cur == this && cur->proc == curproc) {
  321.               *prev = cur->next;
  322.               if (cur->next) {
  323.                   cur->next->when += this->when;
  324.               }
  325.               disposetimeout(this);
  326. !             break;
  327.           }
  328.           prev = &cur->next;
  329.       }
  330.   }
  331.   
  332.   /*
  333. --- 215,259 ----
  334.       TIMEOUT *this;
  335.   {
  336.       TIMEOUT *cur, **prev;
  337. +     short sr = spl7();
  338. +     
  339. +     prev = &tlist;
  340. +     for (cur = tlist; cur; cur = cur->next) {
  341. +         if (cur == this && (cur->proc == curproc)) {
  342. +             *prev = cur->next;
  343. +             if (cur->next) {
  344. +                 cur->next->when += this->when;
  345. +             }
  346. +             spl (sr);
  347. +             disposetimeout(this);
  348. +             return;
  349. +         }
  350. +         prev = &cur->next;
  351. +     }
  352. +     spl(sr);
  353. + }
  354. + void ARGS_ON_STACK
  355. + cancelroottimeout(this)
  356. +     TIMEOUT *this;
  357. + {
  358. +     TIMEOUT *cur, **prev;
  359. +     short sr = spl7();
  360.       
  361.       prev = &tlist;
  362.       for (cur = tlist; cur; cur = cur->next) {
  363. !         if (cur == this && (cur->proc == rootproc)) {
  364.               *prev = cur->next;
  365.               if (cur->next) {
  366.                   cur->next->when += this->when;
  367.               }
  368. +             spl (sr);
  369.               disposetimeout(this);
  370. !             return;
  371.           }
  372.           prev = &cur->next;
  373.       }
  374. +     spl(sr);
  375.   }
  376.   
  377.   /*
  378. ***************
  379. *** 170,175 ****
  380. --- 296,302 ----
  381.       long delta;
  382.       void (*evnt) P_((PROC *));
  383.       TIMEOUT *old;
  384. +     short sr;
  385.   
  386.   /* do the once per second things */
  387.       while (our_clock < 0) {
  388. ***************
  389. *** 180,201 ****
  390.           reset_priorities();
  391.       }
  392.   
  393.   /* see if there are outstanding timeout requests to do */
  394.       while (tlist && ((delta = tlist->when) <= 0)) {
  395.           p = tlist->proc;
  396. -         TRACE(("doing timeout code for pid %d", p->pid));
  397.           evnt = tlist->func;
  398.           old = tlist;
  399.           tlist = tlist->next;
  400. -         disposetimeout(old);
  401. -     /* call the timeout function */
  402. -         (*evnt)(p);
  403.   /* if delta < 0, it's possible that the time has come for the next timeout
  404. !    to occur */
  405.           if (tlist)
  406.               tlist->when += delta;
  407.       }
  408.   }
  409.   
  410.   /*
  411. --- 307,335 ----
  412.           reset_priorities();
  413.       }
  414.   
  415. +     sr = spl7();
  416.   /* see if there are outstanding timeout requests to do */
  417.       while (tlist && ((delta = tlist->when) <= 0)) {
  418.           p = tlist->proc;
  419.           evnt = tlist->func;
  420.           old = tlist;
  421.           tlist = tlist->next;
  422.   /* if delta < 0, it's possible that the time has come for the next timeout
  423. !  * to occur.
  424. !  * ++kay: moved this before the timeout fuction is called, in case the
  425. !  * timeout function installes a new timeout. */
  426.           if (tlist)
  427.               tlist->when += delta;
  428. +         spl(sr);
  429. + /* ++kay: debug output at spl7 hangs the system, so moved it here */
  430. +         TRACE(("doing timeout code for pid %d", p->pid));
  431. +         disposetimeout(old);
  432. +     /* call the timeout function */
  433. +         (*evnt)(p);
  434. +         sr = spl7();
  435.       }
  436. +     spl(sr);
  437.   }
  438.   
  439.   /*
  440.